package web.stu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import web.stu.model.entity.Course;

import java.util.List;

/**
 * @author administer
 * @description 针对表【course(课程表)】的数据库操作Mapper
 * @createDate 2025-05-13 19:55:14
 * @Entity web.stu.model.entity.Course
 */
@Mapper
public interface CourseMapper extends BaseMapper<Course> {

    /**
     * 根据学生id列表查询所包含的所有课程
     *
     * @param studentIds
     * @return
     */
    List<Integer> getCourseIdsByStudentId(@Param("studentIds") List<Integer> studentIds);

    /**
     * 根据教师id查询所有课程id
     *
     * @param teacherId
     * @return
     */
    List<Integer> getCourseIdsByTeacherId(@Param("teacherId") Integer teacherId);

    /**
     * 查询学生选课是否存在该课程id
     *
     * @param courseId
     * @return
     */
    @Select("select count(*) from student_course where course_id = #{courseId}")
    Integer countCourseStudentCourse(@Param("courseId") Integer courseId);

    /**
     * 查询 教师授课表是否存在该课程id
     *
     * @param courseId
     * @return
     */
    @Select("select count(*) from teacher_course where course_id = #{courseId}")
    Integer countCourseTeacherCourse(@Param("courseId") Integer courseId);

    /**
     * 根据学生id 与教师id 班级id 查询 该教师 教授并且该课程学生选择的课程
     *
     * @param studentId
     * @return
     */
    @Select(" select * from course where id in (select sc.course_id from student_course sc inner join teacher_course tc on sc.course_id = tc.course_id where sc.student_id = #{studentId} and tc.class_id = #{classId} and tc.teacher_id = #{teacherId})")
    List<Integer> listCourseIdsByStudentId(@Param("studentId") Integer studentId, @Param("teacherId") Integer teacherId, @Param("classId") Integer classId);


    /**
     * 查询教师是否为此班级此课程授课
     *
     * @param teacherId
     * @param classId
     * @param courseId
     * @return
     */
    @Select("select count(*) from teacher_course where teacher_id = #{teacherId} and class_id = #{classId} and course_id = #{courseId} ")
    Integer getCountByTeacherClassCourseId(@Param("teacherId") Integer teacherId,
                                           @Param("classId") Integer classId,
                                           @Param("courseId") Integer courseId);


    /**
     * 判断学生是否选择课程
     *
     * @param studentId
     * @return
     */
    @Select("select count(*) from student_course where student_id = #{studentId} and course_id = #{courseId}")
    Integer getCountByStudentCourseId(@Param("studentId") Integer studentId, @Param("courseId") Integer courseId);

    /**
     * 根据学生 课程id 查询课程老师名称
     *
     * @param studentId
     * @param courseId
     * @return
     */
    String getTeacherByStudentCourse(@Param("studentId") Integer studentId,@Param("courseId") Integer courseId);
}




